﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>驰骋工作流引擎ccbpm6 </title>
    <script language="JavaScript" src="../../../Comm/JScript.js" type="text/javascript"></script>
    <script language="JavaScript" src="../../../Comm/JS/Calendar/WdatePicker.js" defer="defer"
        type="text/javascript"></script>
    <link href="../../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <link rel="shortcut icon" href="../../../Img/ccbpm.ico" type="image/x-icon" />
    <link href="../../../Comm/Style/CommStyle.css" rel="stylesheet" type="text/css" />
    <link href="../../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../../../Scripts/config.js"></script>
    <script type="text/javascript" src="../../../Comm/Gener.js"></script>
    <script type="text/javascript" src="../../../Scripts/QueryString.js"></script>
    <script type="text/javascript">
        //页面启动函数.
        $(function () {

            var frmID = GetQueryString("FK_MapData");

            //定义主键值.
            var pkval = "PageLoadFull_" + frmID;

            var mapExt = new Entity("BP.Sys.MapExt");
            mapExt.SetPKVal(pkval);
            mapExt.RetrieveFromDBSources();

            //给主键赋值.
            $("#TB_Tag").val(mapExt.Tag);

            //求从表个数
            var mapDtls = new Entities("BP.Sys.MapDtls");
            mapDtls.Retrieve("FK_MapData", frmID);
            var sqls = mapExt.Tag1.split('*');

            var html = "";
            for (var i = 0; i < mapDtls.length; i++) {
                var mapDtl = mapDtls[i];
                html += "<h4>填充从表:" + mapDtl.No + " " + mapDtl.Name + "</h4>";

                var sqlVal = '';

                for (var idx = 0; idx < sqls.length; idx++) {

                    var sql = sqls[idx];
                    if (sql == null || sql == "")
                        continue;

                    var key = sql.substring(0, sql.indexOf('='));
                    if (key == mapDtl.No) {
                        sqlVal = sql.substring(sql.indexOf('=') + 1);
                        break;
                    }
                }

                html += "<textarea id='TB_" + mapDtl.No + "' >" + sqlVal + "</textarea>";
            }

            $("#dtls").html(html);

        });
        //执行保存
        function save_Tag() {

            var frmID = GetQueryString("FK_MapData");

            //定义主键值.
            var pkval = "PageLoadFull_" + frmID;

            var mapExt = new Entity("BP.Sys.MapExt");
            mapExt.SetPKVal(pkval);
            mapExt.Tag = document.getElementById("TB_Tag").value; ;
            mapExt.FK_MapData = frmID;
            mapExt.ExtType = "PageLoadFull";

            //求从表信息.
            //求从表个数
            var mapDtls = new Entities("BP.Sys.MapDtls");
            mapDtls.Retrieve("FK_MapData", frmID);

            var sqls = "";
            for (var i = 0; i < mapDtls.length; i++) {
                var mapDtl = mapDtls[i];
                var val = $("#TB_" + mapDtl.No).val();
                sqls += "*" + mapDtl.No + "=" + val;
            }

            mapExt.Tag1 = sqls;
            mapExt.Save();
            alert("保存成功.");


        }
    </script>
    <base target="_self" />
</head>
<body class="easyui-layout" style='overflow:auto'>
    <form method="post" action="" id="form1" >
    <div id="mainPanel" class="mainPanel">
        <table class='Table' cellspacing='0' cellpadding='0' border='0' style='width: 100%'>
            <tr>
                <td class='GroupTitle'>
                    主表SQL设置<div style='float: right'>
                        <a href='' target="_blank">
                            <img src='/WF/Img/Help.gif'>帮助</a></div>
                </td>
            </tr>
            <tr>
                <td>
                    <textarea name="TB_Tag" rows="7" cols="70" id="TB_Tag" style="width: 99%;">
</textarea>
                    <br />
                    说明:填充主表的sql,表达式里支持@变量与约定的公用变量。
                    <br />
                    比如: SELECT No,Name,Tel FROM Port_Emp WHERE No='@WebUser.No' , 如果列名与开始表单字段名相同，就会自动给值。
                </td>
            </tr>
            <tr>
                <td>
                    <div id="dtls">
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <a id="Btn_Save" class="easyui-linkbutton" onclick="save_Tag()">保存</a>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
